/**
 *    Copyright (C) 2008, 2009 Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_BTREE_MODEL_BASE_HPP
#define	_CUBEFS_CORE_BTREE_MODEL_BASE_HPP

#include <cubefs/core/container/model.hpp>
#include <cubefs/core/container/names.hpp>
#include <cubefs/core/btree/macros.hpp>
#include <cubefs/core/tools/types/algo.hpp>

#include <iostream>

namespace cubefs    {
namespace ctr       {


CUBEFS_BTREE_MODEL_BASE_CLASS_BEGIN(BTreeModelBase)

    typedef typename Base::Name                                                 Name;
    typedef typename Base::Types                                                Types;
    typedef typename Types::KeysList                                            KeysList;
    typedef typename Types::Value                                               Value;

    typedef typename Base::PageMgr                                              PageMgr;
    typedef typename PageMgr::Page                                              Page;
    typedef typename Page::ID                                                   ID;

    typedef typename Base::Iterator                                             Iterator;
    
    typedef typename Types::NodeBase                                            NodeBase;
    typedef typename Types::NodeBase::Base                                      TreeNodePage;
    typedef typename Types::Counters                                            Counters;

    typedef typename Types::Pages::NodeDispatcher                               NodeDispatcher;
    typedef typename Types::Pages::RootDispatcher                               RootDispatcher;
    typedef typename Types::Pages::LeafDispatcher                               LeafDispatcher;
    typedef typename Types::Pages::NonLeafDispatcher                            NonLeafDispatcher;

    typedef typename Types::Pages::Node2RootMap                                 Node2RootMap;
    typedef typename Types::Pages::Root2NodeMap                                 Root2NodeMap;

    typedef typename Types::Pages::NodeFactory                                  NodeFactory;


    typedef typename MaxElement<KeysList, TypeSizeValueProvider>::Result        Key;

    typedef typename cubefs::api::TypedWrapperFactory<Key>::Type                ApiKeyType;

    typedef typename IfThenElse<
                IfTypesEqual<Value, ID>::Value,
                TypedIDValueImpl,
                typename IfThenElse<
                    ValueTraits<Value>::IsPrimitive,
                    TypedNumberImpl<Value>,
                    ValueTypeIsNotSupported<Value>
                >::Result
    >::Result                                                                   ApiValueType;

    typedef typename TypeLocator<Profile, BTreeRootMetadataFactory<Name> >::Type Metadata;

    static const Int  Indexes                                                   = Types::Indexes;
    static const bool MapType                                                   = Types::MapType;

CUBEFS_BTREE_MODEL_BASE_CLASS_END


}
}

#endif
